package thread.sync1;

public class SyncDemo1 {
    public static void main(String[] args) {
        Table t=new Table();
        Thread t1=new Thread(){
            @Override
            public void run() {
                while(true){
                    int bean = t.getBean();
                    Thread.yield();//主动要求线程放弃本次剩余时间片.模拟执行到这里时没时间发生切换
                    System.out.println(getName()+":"+bean);
                }
            }
        };

        Thread t2=new Thread(){
            @Override
            public void run() {
                while(true){
                    int bean = t.getBean();
                    Thread.yield();//主动要求线程放弃本次剩余时间片.模拟执行到这里时没时间发生切换
                    System.out.println(getName()+":"+bean);
                }
            }
        };
        t1.start();
        t2.start();
    }

}
